package cn.gwm.flink.streaming.dwd.check;

import cn.gwm.flink.streaming.constant.BaseFields;
import cn.gwm.flink.streaming.dwm.charge.util.ModeCodeUtil;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @ClassName ReplenishField
 * @Description 补充字段
 * @Author LiangGuang
 * @Date 2023/05/18 10:52
 */
@Slf4j
public class ReplenishField {
    /**
     * 车牌号
     */
    private static final String LICENSE_PLATE = "license_plate";
    /**
     * 电池容量
     */
    private static final String PACK_CAPACITY = "pack_capacity";
    /**
     * 电池类型
     */
    private static final String CELL_BATTERY_TYPE = "cell_battery_type";
    /**
     * cc码
     */
    private static final String MODEL_CODE = "model_code";

    public static void replenish(JSONObject sourceData) {
        String vin = sourceData.getStr(BaseFields.vin);
        Map<String, String> map = ModeCodeUtil.batteryData(vin);

        // 合规性问题，暂时屏蔽牌照信息
//        if (!sourceData.containsKey(LICENSE_PLATE) || BaseFields.defaultVal.equals(sourceData.getStr(LICENSE_PLATE))) {
//            sourceData.set(LICENSE_PLATE, map.get("licensePlate"));
//        }
        if (!sourceData.containsKey(MODEL_CODE) || BaseFields.defaultVal.equals(sourceData.getStr(MODEL_CODE))) {
            sourceData.set(MODEL_CODE, map.get("modelCode"));
        } else {
            // todo  如果 model_code 存在 但是 和溯源不一致，则提示 --> 此处可能添加其他的提示 ，钉钉 ，监控系统等
            if (!sourceData.getStr(MODEL_CODE).equals(map.get("modelCode"))) {
                log.warn(" vin :" + vin + " original model_code is " + sourceData.getStr(MODEL_CODE) + " but idc batteryData is " + map.get("modelCode"));
            }
        }
        if (!sourceData.containsKey(PACK_CAPACITY) || BaseFields.defaultVal.equals(sourceData.getStr(PACK_CAPACITY))) {
            sourceData.set(PACK_CAPACITY, map.get("packCapacity"));
        }
        if (!sourceData.containsKey(CELL_BATTERY_TYPE) || BaseFields.defaultVal.equals(sourceData.getStr(CELL_BATTERY_TYPE))) {
            sourceData.set(CELL_BATTERY_TYPE, map.get("cellBatteryType"));
        }

    }
}
